/*
 *
 * Copyright (C) 2012 Walter Lütgenau
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 */
package offset.nodes.client.chooser.model;

import java.io.Serializable;
import javax.jcr.Node;
import javax.jcr.RepositoryException;
import offset.nodes.Constants;


public class FolderNode implements Serializable {
    private String name;
    private String type;
    private String path;
    private String uuid;
    private boolean hasChildren;

    public FolderNode(Node node) throws RepositoryException {
        name = node.getName();
        path = node.getPath();
        hasChildren = node.hasNodes();
        if (node.isNodeType(Constants.JCR_REFERENCEABLE))
            uuid = node.getUUID();
        type = node.getPrimaryNodeType().getName();
    }

    public FolderNode(String path, boolean hasChildren, String uuid, String type) {
        String[] names = path.split(Constants.PATH_SEPARATOR);
        if (names.length == 0)
            this.name = "";
        else
            this.name = names[names.length-1];
        this.path = path;
        this.hasChildren = hasChildren;
        this.uuid = uuid;
        this.type = type;
    }
    
    public String getName() {
        return name;
    }
    
    public void setName(String name) {
        this.name = name;
    }
    
    public boolean hasChildren() {
        return hasChildren;
    }
    
    public void setHasChildren(boolean hasChildren) {
        this.hasChildren = hasChildren;
    }
    
    public String getType() {
        return type;
    }
    
    public void setType(String type) {
        this.type = type;
    }
    
    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }

    public String getUuid() {
        return uuid;
    }

    public void setUuid(String uuid) {
        this.uuid = uuid;
    }

    public String toString() {
        return getName();
    }
}
